'use strict'

class delTecho {
    constructor() {
        this.param = '/*'
    }
    //创建资源
    async get(c) {
        //根据建议id删除建议
        var techo_id = c.param.starPath;
        try {
            let sqltext3 = `SELECT * FROM techo_sticker WHERE techo_id = ${techo_id}`
            var r3 = await c.service.psql.query(sqltext3);
            for (var i = 0; i < r3.rows.length; i++) {
                let sqltext2 = `DELETE FROM techo_sticker WHERE sticker_id = ${r3.rows[i].sticker_id}`
                var r2 = await c.service.psql.query(sqltext2);
            }

            let sqltext4 = `SELECT * FROM techo_picture WHERE techo_id = ${techo_id}`
            var r4 = await c.service.psql.query(sqltext4);
            for (var j = 0; j < r4.rows.length; j++) {
                let sqltext5 = `DELETE FROM techo_picture WHERE picture_id = ${r4.rows[j].picture_id}`
                var r5 = await c.service.psql.query(sqltext5);
            }

            let sqltext6 = `SELECT * FROM techo_shade WHERE techo_id = ${techo_id}`
            var r6 = await c.service.psql.query(sqltext6);
            for (var x = 0; x < r6.rows.length; x++) {
                let sqltext7 = `DELETE FROM techo_shade WHERE shade_id = ${r6.rows[x].shade_id}`
                var r7 = await c.service.psql.query(sqltext7);
            }

            let sqltext8 = `SELECT * FROM techo_word WHERE techo_id = ${techo_id}`
            var r8 = await c.service.psql.query(sqltext8);
            for (var y = 0; y < r8.rows.length; y++) {
                let sqltext9 = `DELETE FROM techo_word WHERE word_id = ${r8.rows[y].word_id}`
                var r9 = await c.service.psql.query(sqltext9);
            }

            let sqltext1 = `DELETE FROM techo WHERE techo_id = ${techo_id}`
            var r1 = await c.service.psql.query(sqltext1);
            return c.send("success")
        }
        catch (err) {
            return c.status(500).send('error');
        }
    }
}

module.exports = delTecho